package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.RecRecordAdapter;
import flc.ast.bean.MyRecRecordBean;
import flc.ast.databinding.ActivityRecRecordBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.event.EventStatProxy;

public class RecRecordActivity extends BaseAc<ActivityRecRecordBinding> {

    private List<MyRecRecordBean> listShow = new ArrayList<>();
    private RecRecordAdapter recordAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_rec_record;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        mDataBinding.ivRecRecordBack.setOnClickListener(v -> onBackPressed());
        mDataBinding.tvRecRecordClear.setOnClickListener(this);
        mDataBinding.rvRecordList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        recordAdapter = new RecRecordAdapter();
        mDataBinding.rvRecordList.setAdapter(recordAdapter);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvRecRecordClear:
                listShow.clear();
                AppSpUtils.saveRecRecordList(listShow);
                getData();
                break;
        }
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        listShow.clear();
        List<MyRecRecordBean> listSp = AppSpUtils.getRecRecordList();
        if (listSp != null && listSp.size() > 0) {
            listShow.addAll(listSp);
            recordAdapter.setList(listShow);
            mDataBinding.tvRecordNoData.setVisibility(View.VISIBLE);
            mDataBinding.tvRecordNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvRecordList.setVisibility(View.GONE);
            mDataBinding.tvRecRecordClear.setVisibility(View.VISIBLE);
        }
    }

}